package com.demo.Main.StageOne;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class DemoSocket {
        public static void main(String[] args) {
        try {
            Socket socket = new Socket("www.kugou.com", 80);
            DataOutputStream out = new DataOutputStream(socket.getOutputStream());

            out.writeBytes("GET / HTTP/1.1\r\n");
            //out.writeBytes("Host: www.baidu.com\r\n");
            out.writeBytes("Connection: close\r\n\r\n");
            out.writeBytes("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36\r\n");

            out.flush();
            //out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String inputLine;
            StringBuilder html = new StringBuilder();

            while ((inputLine = in.readLine()) != null) {
                html.append(inputLine);
            }

            in.close();
            socket.close();
            System.out.println(html.toString());

            // System.out.println(html.substring(9,12));
        } catch (IOException e) {
            e.printStackTrace();
        }}
}
